﻿using MyCompany.MyProject.Model;
using SqlSugar;
using System.Linq.Expressions;

namespace MyCompany.MyProject.IService;

public interface IBaseService<TEntity> where TEntity : class
{
    ISqlSugarClient Db { get; }
    Task<long> Add(TEntity entity);
 
    Task<List<long>> AddSplit(TEntity entity);
    //Task<List<TEntity>> Query();
    Task<List<TEntity>> Query(Expression<Func<TEntity, bool>>? whereExpression = null);
    Task<List<TEntity>> QuerySplit(Expression<Func<TEntity, bool>> whereExpression, string orderBy = "");

    Task<List<TEntity>> QueryWithCache(Expression<Func<TEntity, bool>>? whreExpression = null);

    /// <summary>
    /// 根据id获取一个对象
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task<TEntity> QueryById(object id);
    /// <summary>
    /// 根据id获取一个对象
    /// </summary>
    /// <param name="id">id</param>
    /// <param name="blnUseCache">是否使用缓存</param>
    /// <returns></returns>
    Task<TEntity> QueryById(object id, bool blnUseCache = false);

    Task<List<TEntity>> QueryByIDs(long[] lstIds);

    /// <summary>
    /// 分页查询数据列表
    /// </summary>
    /// <param name="whereExpression">过滤条件</param>
    /// <param name="pageIndex">分页索引</param>
    /// <param name="pageSize">每页大小</param>
    /// <param name="orderByFields">排序字段</param>
    /// <returns></returns>
    Task<PageModel<TEntity>> QueryPage(Expression<Func<TEntity,bool>>? whereExpression = null,int pageIndex=1,int pageSize =10,string? orderFields=null);

    /// <summary>
    /// 根据id批量删除数据
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task<bool> DeleteByIds(object[] ids);

    /// <summary>
    /// 批量添加数据
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<List<long>> Add(List<TEntity> entity);

    /// <summary>
    /// 更新数据
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> Update(TEntity entity);

    Task<bool> Update(List<TEntity> model);
}
